package com.ywd.materials.admin.controller;

import cn.hutool.core.util.ObjectUtil;
import com.ywd.materials.admin.common.Common;
import com.ywd.materials.admin.dto.query.FirstPageOneOneQuery;
import com.ywd.materials.admin.dto.query.FirstPageOneQuery;
import com.ywd.materials.admin.dto.query.MaterialsWarehouseOneQuery;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.exception.RPage;
import com.ywd.materials.admin.service.impl.FirstPageServiceImpl;
import com.ywd.materials.admin.service.impl.MaterialsWarehouseServiceImpl;
import com.ywd.materials.admin.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author:lk
 * @Date: 2025/11/13  00:25
 */
@AllArgsConstructor
@RestController
@RequestMapping("/firstPage")
@Tag(name = "首页")
public class FirstPageController {

    private final FirstPageServiceImpl firstPageServiceImpl;


    //仓库等级列表
    @GetMapping("/getWarehouseGradeList")
    @Operation(summary = "1.仓库等级列表")
    public R<List<Map<String, String>>> getWarehouseGradeList() {
        return R.ok(firstPageServiceImpl.getWarehouseGradeList());
    }

    @PostMapping("/getWarehouseTree")
    @Operation(summary = "2.仓库列表(树形)")
    public R<List<MaterialsWarehouseTreePartVo>> getWarehouseTree(@RequestBody FirstPageOneOneQuery query) {
        return R.ok(firstPageServiceImpl.getWarehouseTree(query));
    }

    @GetMapping("/getOneStatistics")
    @Operation(summary = "3.物资分类占比统计")
    public R<FirstPageOneVo> getOneStatistics(@Schema(description = "所属区县")
                                              @RequestParam(required = false) String areaName,
                                              @Schema(description = "仓库所属等级(-1=全部, 0=市本级, 1=区县级, 2=乡镇级, 3=村点级)")
                                              @RequestParam(required = false) String gradeValue,
                                              @Schema(description = "仓库ID")
                                              @RequestParam(required = false) Long warehouseId) {
        return R.ok(firstPageServiceImpl.getOneStatistics(areaName, gradeValue, warehouseId));
    }

    @GetMapping("/getTwoStatistics")
    @Operation(summary = "4.仓库库存总量排名")
    public R<List<FirstPageTwoVo>> getTwoStatistics(@Schema(description = "所属区县")
                                                    @RequestParam(required = false) String areaName,
                                                    @Schema(description = "仓库所属等级(-1=全部, 0=市本级, 1=区县级, 2=乡镇级, 3=村点级)")
                                                    @RequestParam(required = false) String gradeValue,
                                                    @Schema(description = "仓库ID")
                                                    @RequestParam(required = false) Long warehouseId) {
        return R.ok(firstPageServiceImpl.getTwoStatistics(areaName, gradeValue, warehouseId));
    }

    @GetMapping("/getThreeStatistics")
    @Operation(summary = "5.物资用量TOP5")
    public R<List<FirstPageThreeVo>> getThreeStatistics(@Schema(description = "所属区县")
                                                        @RequestParam(required = false) String areaName,
                                                        @Schema(description = "仓库所属等级(-1=全部, 0=市本级, 1=区县级, 2=乡镇级, 3=村点级)")
                                                        @RequestParam(required = false) String gradeValue,
                                                        @Schema(description = "仓库ID")
                                                        @RequestParam(required = false) Long warehouseId) {
        return R.ok(firstPageServiceImpl.getThreeStatistics(areaName, gradeValue, warehouseId));
    }

    @GetMapping("/getFourStatistics")
    @Operation(summary = "6.出入库统计记录")
    public R<List<FirstPageFourVo>> getFourStatistics(@Schema(description = "所属区县")
                                                      @RequestParam(required = false) String areaName,
                                                      @Schema(description = "仓库所属等级(-1=全部, 0=市本级, 1=区县级, 2=乡镇级, 3=村点级)")
                                                      @RequestParam(required = false) String gradeValue,
                                                      @Schema(description = "仓库ID")
                                                      @RequestParam(required = false) Long warehouseId) {
        return R.ok(firstPageServiceImpl.getFourStatistics(areaName, gradeValue, warehouseId));
    }


    @GetMapping("/getFiveStatistics")
    @Operation(summary = "7.最近出入库记录")
    public R<List<FirstPageFiveVo>> getFiveStatistics(@Schema(description = "所属区县")
                                                      @RequestParam(required = false) String areaName,
                                                      @Schema(description = "仓库所属等级(-1=全部, 0=市本级, 1=区县级, 2=乡镇级, 3=村点级)")
                                                      @RequestParam(required = false) String gradeValue,
                                                      @Schema(description = "仓库ID")
                                                      @RequestParam(required = false) Long warehouseId) {
        return R.ok(firstPageServiceImpl.getFiveStatistics(areaName, gradeValue, warehouseId));
    }

    @GetMapping("/getSixStatistics")
    @Operation(summary = "8.数据统计")
    public R<FirstPageSixVo> getSixStatistics(@Schema(description = "所属区县")
                                              @RequestParam(required = false) String areaName,
                                              @Schema(description = "仓库所属等级(-1=全部, 0=市本级, 1=区县级, 2=乡镇级, 3=村点级)")
                                              @RequestParam(required = false) String gradeValue,
                                              @Schema(description = "仓库ID")
                                              @RequestParam(required = false) Long warehouseId,
                                              @Schema(description = "是否显示待入库物资(false=关闭, true=开启)")
                                              @RequestParam(required = false) Boolean openIn) {
        return R.ok(firstPageServiceImpl.getSixStatistics(areaName, gradeValue, warehouseId, openIn));
    }

    @GetMapping("/getSevenStatistics")
    @Operation(summary = "9.区县数据")
    public R<List<FirstPageSevenVo>> getSevenStatistics() {
        return R.ok(firstPageServiceImpl.getSevenStatistics());
    }


}
